<!--show search page create by pionner at Mon Dec 08 14:26:34 CST 2008-->
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
	<base href="<%=basePath%>">
	<title>Process</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<link rel='stylesheet' href='css/style.css'>
	<link rel='stylesheet' type='text/css' href='css/table.css'>
	<script src='js/alai_tree/alai_tree.js'></script>
	<script src='js/alai_tree/alai_tree_pretty.js'></script>
	<script src='js/alai_tree/alai_tree_check.js'></script>
	<script src='js/prototype-1.4.0.js'></script>
	<script src='js/InputTool.js'></script>
	<script src='js/comm.js'></script>
	<title>Tree</title>
	</head>
	<body>
		<table width='100%' height='100%' border='0'>
			<tr>
				<td width='20%' background='images/treebg.gif' valign='top' bordercolor='#7d7be3'>
					<table><tr>
						<td>选择操作：</td>
						<td colspan='10'>
							<select name='selectFun' onchange='fireFun()' >
								<!-------------add link here for the tree-------------->
								<option value='detail' selected>查看null</option>
								<option value='add'>添加null</option>
								<option value='edit'>编辑null</option>
								<option value='fresh'>刷新null树</option>
							</select>
						</td>
					</tr></table>
				</td>
				<td width='80%' bordercolor='#b4fef4'>
					<iframe width='100%' frameborder='0' height='100%' name='departmentworkPlace' src=''></iframe>
				</td>
			</tr>
		</table>
	</body>
</html>

<script>
var tree1=new alai_tree_pretty(divTree1)
var root=tree1.root
function setFun(){
	var functionf=getSelectValue(document.all.selectFun);
	if('add'==functionf){
		processAdd();
	}else if('detail'==functionf){
		if(!validateSelTree())return false;
		processDetail();
	}else if('member'==functionf){//手工添加的方法
		if(!validateSelTree())return false;


	}else if('edit'==functionf){
		if(!validateSelTree())return false;
		processEdit();
	}
}
function validateSelTree(){
	var treeNode=tree1.getSelectedNode();
	if(!treeNode){
		alert('请选择一个null);
		return false;
	}
}

function fireFun(){
	setFun();
	var functionf=getSelectValue(document.all.selectFun);
	if('fresh'==functionf){
		freshTree();
	}
}

function loadTreeNode(pidNode){
	var pid='-1';
	if(pidNode.body)pid=pidNode.body.pid
	var url="<%=request.getContextPath()%>/processtreenode.action?pid="+pid;
	var myAjax = new Ajax.Request(
		url, 
		{ 
			method: 'get',
			asynchronous:false
	});
	var myXML = myAjax.transport.responseXML;
	addNodeToTree(myXML,pidNode);
}

function addNodeToTree(doc,pidNode){
	var nodes=doc.selectNodes("TREENODES/TREENODE");
	if(nodes.length>0){
		var node,treeNode;
		for(var i=0;i<nodes.length;i++){
			node=nodes[i];
			treeNode=pidNode.add(node.getAttribute('name'));
			treeNode.expand(false);
			treeNode.body.flg=0;
			treeNode.body.pid=node.getAttribute('id')
			treeNode.icon.src='js/alai_tree/images/fold_close.gif'
		}
	}
}

function treeClkListener(){
	function treeClkListener(){
		var flg=treeNode.body.flg;
		if(0==flg){
			loadTreeNode(treeNode);
			treeNode.body.flg=1;
			treeNode.expand();
		}
		treeNode.expand();
		if(treeNode.expanded)treeNode.icon.src='js/alai_tree/images/fold_open.gif'
		setFun();
	}
}

treeClkListener()

function processAdd(){
	var treeNode=tree1.getSelectedNode();
	var objid="-1"
	if(treeNode){
		objid=treeNode.body.pid
	}
	document.all.departmentworkPlace.src="processAdd.action?fromTree=1&pid="+objid
}

function processEdit(){
	var treeNode=tree1.getSelectedNode();
	var objid="-1"
	if(treeNode){
		objid=treeNode.body.pid
	}
	document.all.departmentworkPlace.src="processEdit.action?fromTree=1&pid="+objid
}

function processDetail(){
	var treeNode=tree1.getSelectedNode();
	var objid="-1"
	if(treeNode){
		objid=treeNode.body.pid
	}
	document.all.departmentworkPlace.src="processDetail.action?fromTree=1&pid="+objid
}
loadTreeNode(root);
function freshTree(){
	divTree1.innerHTML='';
	tree1=new alai_tree_pretty(divTree1)
	root=tree1.root
	loadTreeNode(root);
	treeClkListener();
}
</script>
